{template 'web/common/common'}
{template 'web/order/navbar'}
<link rel="stylesheet" type="text/css" href="../addons/{php echo $_GPC['m']}/resource/swal/dist/sweetalert2.min.css" />
<link rel="stylesheet" type="text/css" href="../addons/kundian_farm/resource/css/layui.css" />
<link rel="stylesheet" type="text/css" href="../addons/kundian_farm/resource/css/new-common.css" />
<style>
</style>
<div class="layui-form">
    <table class="layui-table" style="width: 500px;float: left;">
        <caption>订单信息</caption>
        <colgroup>
            <col width="60">
            <col width="200">
            <col>
        </colgroup>
        <tbody>
        <tr>
            <td style="text-align: right;">订单编号:</td>
            <td>{$orderData['order_number']}</td>
        </tr>
        <tr>
            <td style="text-align: right;">下单时间</td>
            <td><?php echo date("Y-m-d H:i:s",$orderData['create_time']);?></td>
        </tr>
        <tr>
            <td style="text-align: right;">用户</td>
            <td>{$orderData['uid']}</td>
        </tr>
        <tr>
            <td style="text-align: right;">支付方式</td>
            <td>{$orderData['pat_method']}</td>
        </tr>
        <tr>
            <td style="text-align: right;">收货信息</td>
            <td>
                <p>姓名：{$orderData['name']}</p>
                <p>联系电话：{$orderData['phone']}</p>
                <p>收货地址：{$orderData['address']}</p>
            </td>
        </tr>

        <tr>
            <td style="text-align: right;">快递信息</td>
            <td>
                <p>快递公司：{$orderData['express_company']}</p>
                <p>快递单号：{$orderData['send_number']}</p>
            
            </td>
        </tr>

        <tr>
            <td colspan="2" style="text-align: center;">订单状态</td>
        </tr>
        <tr>
            <td style="text-align: right;">状态</td>
            <td>
                {if $orderData['status']==0}
                <span class="layui-badge layui-bg-gray">未支付</span>
                {else if $orderData['status']==1}
                <span class="layui-badge layui-bg-green">已支付</span>
                {else if $orderData['status']==2}
                <span class="layui-badge layui-bg-green">待收货</span>
                {else if $orderData['status']==3}
                <span class="layui-badge layui-bg-green">已完成</span>
                {else if $orderData['status']==5}
                <span class="layui-badge layui-bg-gray">已取消</span>
                {else if $orderData['status']==4}
                <a href="{url 'site/entry/refund',array('m'=>'kundian_farm','id'=>$item['id'],'version_id'=>$_GPC['version_id'])}">
                    <button type="button" class="cancel-order layui-btn layui-btn-danger">确认取消订单</button></a>
                {/if}
            </td>
        </tr>
        <tr>
            <td style="text-align: right;">支付时间</td>
            <td>
                {if $orderData['pay_time']==0}
                --：--
                {else}
                <?php echo date("Y-m-d H:i:s",$orderData['pay_time']);?>
                {/if}
            </td>
        </tr>
        <tr>
            <td colspan="2" style="text-align: center;">订单金额</td>
        </tr>
        <tr>
            <td style="text-align: right;">总金额</td>
            <td>{$orderData['total_price']}元</td>
        </tr>
        <tr>
            <td style="text-align: right;">运费</td>
            <td>{$orderData['send_price']}元</td>
        </tr>
        <tr>
            <td style="text-align: right;">优惠金额</td>
            <td>{$orderData['coupon_price']}元</td>
        </tr>
        <tr>
            <td style="text-align: right;">实际支付金额</td>
            <td>{$orderData['pra_price']}元</td>
        </tr>
        </tbody>
    </table>

    
    <table class="layui-table" style="width: 900px;float: left;margin-left: 30px;">
        <caption>商品信息</caption>
        <tbody>
        <tr>
            <td>商品编号</td>
            <td>商品封面</td>
            <td>商品名称</td>
            <td>规格</td>
            <td>数量</td>
            <td>小计</td>
        </tr>
        {loop $order_detail $key $value}
        <tr>
            <td>{$value['goods_id']}</td>
            <td><img src="{$value['cover']}" style="width: 40px;height: 40px;" alt=""></td>
            <td>{$value['goods_name']}</td>
            <td>
                {loop $value['specItem'] $k $item}
                {$item['name']}:{$item['spec_value']}
                {/loop}
            </td>
            <td>{$value['count']}</td>
            <td>{$value['price']}元</td>
        </tr>
        {/loop}
        <tr>
            <td colspan="6">
                <input type="hidden" name="order_id" value="<?php echo $orderData['id']?>">
                {if $orderData['status']==1 }
                <div class="layui-form-item">
                    <label class="layui-form-label">快递公司</label>
                    <div class="layui-input-block">
                      <input type="text" name="express_company" value="{$orderData['express_company']}" placeholder="快递公司" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">快递单号</label>
                    <div class="layui-input-block">
                      <input type="text" name="send_number" value="{$orderData['send_number']}" placeholder="快递单号" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <div class="layui-input-block">
                        {if $op=='shop_order_edit'}
                            <button class="layui-btn" id="sendGoods" data-ordertype='1'>立即发货</button>
                        {else if $op=='group_edit'}
                        <button class="layui-btn" id="sendGoods" data-ordertype='2'>立即发货</button>
                        {else if $op=='integral_edit'}
                        <button class="layui-btn" id="sendGoods" data-ordertype='3'>立即发货</button>
                        {else if $op=='animal_edit'}
                        <button class="layui-btn" id="sendGoods" data-ordertype='1'>立即发货</button>
                        {else if $op=='send_edit'}
                        <button class="layui-btn" id="sendGoods" data-ordertype='1'>立即发货</button>
                        {/if}
                    </div>
                  </div>
                {/if}

                {if $orderData['status']==2}
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            {if $op=='shop_order_edit'}
                            <button class="layui-btn" id="confirmGoods" data-ordertype='1'>确认收货</button>
                            {else if $op=='animal_edit'}
                            <button class="layui-btn" id="confirmGoods" data-ordertype='1'>确认收货</button>
                            {else if $op=='send_edit'}
                            <button class="layui-btn" id="confirmGoods" data-ordertype='1'>确认收货</button>
                            {else if $op=='group_edit'}
                            <button class="layui-btn" id="confirmGoods" data-ordertype='2'>确认收货</button>
                            {else if $op=='integral_edit'}
                            <button class="layui-btn" id="confirmGoods" data-ordertype='3'>确认收货</button>
                            
                              {/if}
                        </div>
                      </div>
                {/if}
            </td>
        </tr>
        </tbody>
    </table>
</div>

<script>
    require(["../addons/{php echo $_GPC['m']}/resource/swal/dist/sweetalert2.min.js"],function(){
        $(function(){
            $("#sendGoods").click(function () {
                var ordertype=$(this).attr("data-ordertype");
                var orderid=$("input[name='order_id']").val();
                var send_number=$("input[name='send_number']").val();
                var express_company=$("input[name='express_company']").val();
                if(ordertype==1){
                    var url="{url 'site/entry/'.$_GPC['do'],array('m'=>$_GPC['m'],'op'=>'send_goods','version_id'=>$_GPC['version_id'])}"
                }else if(ordertype==2){
                    var url="{url 'site/entry/'.$_GPC['do'],array('m'=>$_GPC['m'],'op'=>'send_group_goods','version_id'=>$_GPC['version_id'])}"
                }else if(ordertype==3){
                    var url="{url 'site/entry/'.$_GPC['do'],array('m'=>$_GPC['m'],'op'=>'send_integral_goods','version_id'=>$_GPC['version_id'])}"
                }
                if(send_number==''){
                    alert("请填写配送单号！");
                    return false;    
                }else{
                    $.ajax({
                        type:"post",
                        url:url,
                        data:{order_id:orderid,send_number:send_number,express_company:express_company},
                        dataType:'json',
                        success:function(res){
                            if(res.status==1){
                                swal('操作成功!', '操作成功!', 'success');
                            }else{
                                swal('操作失败!', '操作失败!', 'error');
                            }
                        }
                    })
                }
            })
            $("#confirmGoods").click(function () {
                var ordertype=$(this).attr("data-ordertype");
                var orderid=$("input[name='order_id']").val();
                if(ordertype==1){
                    var url="{url 'site/entry/'.$_GPC['do'],array('m'=>$_GPC['m'],'op'=>'confirmGoods','version_id'=>$_GPC['version_id'])}"
                }else if(ordertype==2){
                    var url="{url 'site/entry/'.$_GPC['do'],array('m'=>$_GPC['m'],'op'=>'confirmGroupGoods','version_id'=>$_GPC['version_id'])}"
                }else if(ordertype==3){
                    var url="{url 'site/entry/'.$_GPC['do'],array('m'=>$_GPC['m'],'op'=>'confirmIntegralGoods','version_id'=>$_GPC['version_id'])}"
                }
                $.ajax({
                    type:"post",
                    url:url,
                    data:{order_id:orderid},
                    dataType:'json',
                    success:function(res){
                        if(res.status==1){
                            swal('操作成功!', '操作成功!', 'success');
                        }else{
                            swal('操作失败!', '操作失败!', 'error');
                        }
                    }
                })
            })
    
        })
    })
</script>


